import KoaRouter from 'koa-router'
import {RegController} from '../controllers/register'
const registerRoute=new KoaRouter()

registerRoute.get('/register',async(ctx)=>{
      const data=await new RegController().users()
      ctx.body={
        data,
        message:'ok'
      }
})

registerRoute.post('/register',async(ctx)=>{
  console.log("register路由接收到post请求");
  const payload=ctx.request.body
  console.log("接收到参数",payload);
  // const {id,created} =await new RegController().createUser(payload) 
  let created=await new RegController().createUser(payload) 
  ctx.body={
    created,
    message:'ok'
  }
})
registerRoute.post('/reset',async(ctx)=>{
  console.log("reset路由接收到post请求");
  const payload=ctx.request.body
  console.log("接收到参数",payload);
  // const {id,created} =await new RegController().createUser(payload) 
  let resetRes=await new RegController().resetPwd(payload) 
  console.log(resetRes);
  ctx.body={
    resetRes,
    message:'ok'
  }
})

export{
  registerRoute
} 
